package com.geek.gkfood.biz.jms;

import com.geek.gkfood.framework.mq.AbstractMqListener;
import com.geek.gkfood.service.meal.model.SnatchOrderModel;
import com.geek.gkfood.util.enums.mq.MqEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

/**
 * <h1>抢单下单消息监听器。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2023/9/23 19:53
 */
@Slf4j
@Component
public class SnatchOrderMqListener extends AbstractMqListener<SnatchOrderModel> {

    @StreamListener("input")
    @Override
    public void recvMsg(String recvMsg) {
        super.recvMsg(recvMsg);
    }

    @Override
    protected String getTopicName() {
        return MqEnum.Q_GKFOOD_SNATCHORDER_TOPIC.getCode();
    }

    @Override
    public void doRecvMsg(SnatchOrderModel msgObject) {
        System.out.println("doRecvMsg=" + msgObject);
    }

//    @StreamListener("input")
//    public void recvMsgDraft(String recvMsg) {
//        System.out.println("recvMsgDraft=" + recvMsg);
//    }


//    public static void main(String[] args) throws Exception {
//        // 1、创建消费者对象
//        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("batch_group");
//
//        // 2、为消费者对象设置 NameServer 地址
//        consumer.setNamesrvAddr("127.0.0.1:9876");
//
//        // 3、订阅主题
//        consumer.subscribe("custom-batch-topic", "*");
//
//        // 4、注册监听消息，并打印消息
//        consumer.registerMessageListener(new MessageListenerConcurrently() {
//            @Override
//            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
//                                                            ConsumeConcurrentlyContext context) {
//                for (MessageExt msg : msgs) {
//                    String printMsg = new String(msg.getBody()) + ", recvTime: "
//                            + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
//                    System.out.println(printMsg);
//                }
//
//                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
//            }
//        });
//
//        // 5、把消费者直接启动起来
//        consumer.start();
//        System.out.println("Consumer Started Finished.");
//    }
}